<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改分类')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-type-edit" th:object="${sysType}">
        <input name="id" th:field="*{id}" type="hidden">
        <input id="treeId" name="pid" type="hidden" th:field="*{pid}" />
        <div class="form-group">
            <label class="col-sm-3 control-label">上级分类：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" type="text" id="treeName" onclick="selectTypeTree()" readonly="true" th:field="*{parentname}">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">分类名称：</label>
                <div class="col-sm-8">
                    <input name="typename" th:field="*{name}" class="form-control" type="text">
                </div>
            </div>
        </div>

        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="sort" th:field="*{sort}" class="form-control" type="text">
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <label class="toggle-switch switch-solid">
                        <input  id="state" type="checkbox"  th:checked="${sysType.state == 0 ? true : false}">
                        <span></span>
                    </label>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "system/filter";
    $("#form-type-edit").validate({
        rules:{
            name: "required",

        },
        focusCleanup: true
    });
    /*部门管理-修改-选择部门树*/
    function selectTypeTree() {
        var deptId = $("#treeId").val();
        var excludeId = $("input[name='id']").val();
        if(deptId > 0) {
            var options = {
                title: ' 分类选择',
                width: "380",
                url: prefix + "/selectTypeTree/" + $("#treeId").val() + "/" + excludeId,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        } else {
            $.modal.alertError("父类不能选择");
        }
    }
    function doSubmit(index, layero){
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowLastLevel(tree)) {
            var body = $.modal.getChildFrame(index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            $.modal.close(index);
        }
    }
    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-type-edit").serializeArray();
            var state = $("input[id='state']").is(':checked') == true ? 0 : 1;
            data.push({"name": "state", "value": state});
            $.operate.save(prefix + "/edit", data);
        }
    }

</script>
</body>
</html>